package com.example.mansystem.configuration;

import com.example.mansystem.Interceptor.SessionHandlerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author guocz
 * @date 20210621
 * MVC全局特性
 */

@Configuration
public class MvcConfigurer implements WebMvcConfigurer {

    @Bean
    public SessionHandlerInterceptor setBean2(){
        return new SessionHandlerInterceptor();
    }

    /**
     * 拦截器
     * @param registry 注册
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry){
        List<String> excludePath = new ArrayList<>();
        excludePath.add("/user/login");
        excludePath.add("/user/register");
        excludePath.add("/user/autologin");
        excludePath.add("/user/department");
        registry.addInterceptor(setBean2()).excludePathPatterns(excludePath);
    }

    /**
     * 跨域访问配置
     * @param registry 注册
     */
    @Override
    public void addCorsMappings(CorsRegistry registry){

    }

    /**
     * 格式化
     * @param registry 注册
     */
    @Override
    public void addFormatters(FormatterRegistry registry) {

    }

    /**
     * URI到视图的映射
     * @param registry 注册
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry){

    }

    // 其他更多全局定制接口

}
